package io.github.betwowt.minio.configuration;

import io.github.betwowt.minio.properties.MinioClientProperties;
import io.minio.MinioClient;
import io.minio.errors.InvalidEndpointException;
import io.minio.errors.InvalidPortException;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * @author betwowt
 * @date 2019/04/02
 */
@Configuration
@ConditionalOnProperty(prefix = "minio.server",name = "enabled",havingValue = "true")
public class MinioClientConfiguration {

    private MinioClientProperties properties;

    public MinioClientConfiguration(MinioClientProperties minioClientProperties) {
        this.properties = minioClientProperties;
    }

    @Bean
    public MinioClient minioClient() throws InvalidPortException, InvalidEndpointException {
        MinioClient client = new MinioClient(properties.getEndpoint(),
                properties.getAccessKey(),properties.getSecretKey());
        return client;
    }
}
